package com.apcc4m.sfpush.service;

import com.apcc4m.sfpush.bean.CommandCode;
import com.apcc4m.sfpush.bean.PushMessage;
import com.apcc4m.sfpush.handler.IChannelHandler;
import com.apcc4m.sfpush.listener.NettyServerListener;

public class MessageService {

    protected IChannelHandler handler;
    protected NettyServerListener listener;

    public void init(NettyServerListener listener, IChannelHandler handler) {
        this.listener = listener;
        this.handler = handler;
    }

    /**
     * 收到消息后触发
     * 
     * @param msg
     */
    public void receive(PushMessage msg) {
        switch (msg.getCmd()) {
        case CommandCode.MNG_PUSH_ALL:
            listener.pushToAll(msg);
            break;
        case CommandCode.MNG_PUSH_SINGLE:
            listener.pushSingle(msg.getToId(), msg);
            break;
        }
    }

}
